package edu.gatech.oad.antlab.person;

import java.util.Random;

/**
 *  A simple class for person 2
 *  returns their name and a
 *  modified string 
 *
 * @author Bob
 * @version 1.1
 */
public class Person2 {
    /** Holds the persons real name */
    private String name;
	 	/**
	 * The constructor, takes in the persons
	 * name
	 * @param pname the person's real name
	 */
	 public Person2(String pname) {
	   name = pname;
	 }
	/**
	 * This method should take the string
	 * input and return its characters in
	 * random order.
	 * given "gtg123b" it should return
	 * something like "g3tb1g2".
	 *
	 * @param input the string to be modified
	 * @return the modified string
	 */
	private String calc(String input) {
		//create a new Random object to help with shuffling the
		//  chars in the string
		Random r = new Random();
		//this guy holds the randomly generated index from r
		int tmpIndex;
		//this guy holds the temporary char so we don't lose
		//  data
		char tmp;
		//convert the string into an array of characters
		char[] arrayStr = input.toCharArray();
		//loop through the entire array once
		for(int i = 0; i < arrayStr.length; i++){
			//generate a random index in the array.  We are 
			//  going to swap the current char at index i 
			//  with the randomly generated one at tmpIndex
			tmpIndex = r.nextInt(arrayStr.length);
			//perform a swap w/ a temp char so we don't lose
			//  any of the data
			tmp = arrayStr[i];
			arrayStr[i] = arrayStr[tmpIndex];
			arrayStr[tmpIndex] = tmp;
		}//end for
		//cast the array back into a string and return it.  the string
		//  has now had its chars randomized
		return (new String(arrayStr));
	}
	/**
	 * Return a string rep of this object
	 * that varies with an input string
	 *
	 * @param input the varying string
	 * @return the string representing the 
	 *         object
	 */
	public String toString(String input) {
	  return (name + calc(input));
	}

}
